<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>考神驾到手机站试题练习</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/public.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/windowsheight.js"></script>

<%--    <link rel="stylesheet" href="${pageContext.request.contextPath}/manager_page/layui/css/layui.css" media="all">--%>
    <script src="${pageContext.request.contextPath}/manager_page/layui/layui.js"></script>

    <style type="text/css">
        .myfooter{ background:#15af87; color:#fff; text-align:center; bottom:0;width:100%;}
        .myfooter p{ font-size:1em; line-height:1.5em; padding-top:0.5em}
        .myfooter span{ display:block; font-family:Arial, Helvetica, sans-serif; font-size:0.75em; line-height:1em; padding-bottom:0.5em;}

        .green_bg{
            background-color: #01a474;
        }
        .fix_bottom1{
            position: fixed;
            width: 100%;
            bottom: 0;
        }
        .fix_bottom2{
            position: fixed;
            width: 100%;
            bottom: 1%;
        }
        .a_collect{padding-left:45.50898203592814%; background:url(images/shoucang.png) no-repeat 26.34730538922156% center; background-size:auto 120%;}
        .a_collect_active{padding-left:45.50898203592814%; background:url(images/shoucang2.png) no-repeat 26.34730538922156% center; background-size:auto 120%; color:#ff6600; }


        .mymoresost_con{ width:97.5%; margin:0 auto; height: 294px;overflow-y: scroll;background-color: #e9e9e9;}
        .mymoresost_con span{ width:20%; float:left; font-size:1em; overflow:hidden;}
        .mymoresost_con span a{ width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid #e0e0e0; text-align:center;text-decoration: none;color: DimGray;}

    </style>
</head>

<body>

<input type="hidden" id="question_class_hide" value=${param.question_class_hide}  >
<input type="hidden" id="question_chapter_hide" value=${param.question_chapter_hide} >
<input type="hidden" id="rand_flag" value=${param.rand_flag} >
<input type="hidden" id="other_class" value=${param.other_class} >
<input type="hidden" id="did_class" value=${param.did_class} >

<!-----------头部开始--------------->
<%@ include file="page_head.jsp"%>
<%--隐藏菜单结束--%>
<!-----------头部结束--------------->


<!-----------内容开始--------------->
 <div class="content">
     <div class="test_bigtitle width610"><img src="images/libg_06.jpg"><p ><label id="question_chapter">章节</label><b>（<label id="question_chapter_count1">37</label>题）</b><span><font id="question_chapter_number">1</font>/<label id="question_chapter_count2">37</label></span></p></div>
   <div class="testcontent">
     <div class="width610">
         <p class="title_test" ><label id="question_content">题干</label><span id="many_or_not">[单选题]</span></p>
         <div id="question_img_div"><img id="question_img" class="testimg" src="#"/></div>

         <%--         视频--%>
         <div id="question_video_div">
<%--         <video id="question_video" controls="controls" autoplay="autoplay" hidden="hidden">--%>
<%--             <source id="video_source_1" src="${pageContext.request.contextPath}/img_artificial/question_img/kesi1_1.mp4" type="video/mp4" />--%>
<%--             <source id="video_source_2" src="${pageContext.request.contextPath}/img_artificial/question_img/kesi1_1.ogg" type="video/ogg" />--%>
<%--             <source id="video_source_3" src="${pageContext.request.contextPath}/img_artificial/question_img/kesi1_1.webm" type="video/webm" />--%>
<%--             <object id="video_source_5" data="${pageContext.request.contextPath}/img_artificial/question_img/kesi1_1.mp4" width="320" height="240">--%>
<%--                 <embed id="video_source_4" src="${pageContext.request.contextPath}/img_artificial/question_img/kesi1_1.swf" width="320" height="240" />--%>
<%--             </object>--%>
<%--         </video>--%>
         </div>

        <ul class="option_test" id="question_option_ul">
<%--          <li ><input id="option1" type="checkbox" value="" onclick="uncheck_other(1)" /><p onclick="option_check(1);">A、客车超员 </p></li>--%>
<%--          <li><input id="option2" type="checkbox" value="" onclick="uncheck_other(2)" /><p onclick="option_check(2);">B、超速行驶</p></li>--%>
<%--          <li><input id="option3" type="checkbox" value="" onclick="uncheck_other(3)" /><p onclick="option_check(3);">C、酒后驾驶</p></li>--%>
<%--          <li><input id="option4" type="checkbox" value="" onclick="uncheck_other(4)" /><p onclick="option_check(4);">D、疲劳驾驶</p></li>--%>
<%--            --%>
        </ul>
        <a id="confrim_link" href="javascript:confrim_answer();" class="checkbutton">确认</a>
     </div>
   </div>
     <br>
   <div class="test_buttons width610 scroll_yes">
      <div class="anwser_right green_bg" hidden="hidden" id="answer_feedback_right">答对了，请点击下一题</div>
       <div class="anwser_right" hidden="hidden" id="answer_feedback_wrong">答错了，标准答案是：C</div>
       <br>
        <div class="abouttest_button">
            <a href="javascript:change_next_checkbox();"><p class="goin_next"><input id="next_checkbox" type="checkbox" value="" disabled="disabled"/><span onclick="">答对自动下一题</span></p></a>

            <div class="explain">
            <p class="thisexplain"><a href="javascript:;">本题答案</a></p>
            <p class="collection"><a class="a_collect" id="collect_btn" href="javascript:collect_question();">收藏</a></p>
            <div class="clear"></div>
          </div>
            <a href="javascript:showComment();"><p class="goin_next"><input id="comment_checkbox" type="checkbox" value="" disabled="disabled"/><span>显示评论</span></p></a>

            <div class="clear"></div>
        </div>
       <br>
        <p class="test_pre_next"><a href="javascript:last_question();" class="cant_click"> << 上一题 </a><a href="javascript:next_question();"> 下一题 >> </a></p>
<%--        <div class="shownow">对： 0 题&nbsp;&nbsp;&nbsp;&nbsp;错：1题&nbsp;&nbsp;&nbsp;&nbsp;正确率：0.00%</div>--%>
       <br><br><br><br>
   </div>
  
      
 </div>
 <!-----------内容结束--------------->



 <div class="explain_tan">
     <div class="explain_tan_con">
        <a href="javascript:;" class="close">&nbsp;</a>
        <h1><img src="images/xaingjie03.jpg"/><span>答案：</span></h1>
        <div class="anwser_explain">
         <p >选<span id="question_answer">C</span></p>
        </div>
      </div>
  </div>

<div class="biaoti" id="comment_title_div" hidden="hidden"><img src="images/libg_06.jpg"><span>评论</span></div>

<div id="comment_div" style="height: 100%;width: 100%;float: left;" hidden="hidden">

<%--    <div style="margin-top: 15px;width: 100%;float:left;">--%>
<%--        <div style="float:left;width: 12%;margin-left: 5px;">--%>
<%--            <a href="javascript:to_img_detail('小红',0,'${pageContext.request.contextPath}/img_artificial/user_img/beauty2.jpg');">--%>
<%--                <img src="${pageContext.request.contextPath}/img_artificial/user_img/beauty2.jpg" width="50px" height="50px">--%>
<%--            </a>--%>
<%--        </div>--%>
<%--        <div style="float:right;width: 84%;margin-left: 5px;margin-right: 0px;">--%>
<%--            <div>--%>
<%--                <div style="float:left;width: 80%;"><label style="color: #8D8D8D">小明</label></div>--%>
<%--                <div style="float:right;width: 20%;"><div style="margin-top: 4px;margin-bottom: 0px;float: left;"><label style="color: #8D8D8D;">0 &nbsp;</label></div> <a href="javascript:changeValue_img(1);"><img id="value_img1" src="images/value.png" width="25" height="25"> </a></div>--%>
<%--            </div>--%>
<%--            <div>--%>
<%--                <label style="color: #8D8D8D">评论于：</label><label style="color: #8D8D8D">2022-1-28 下午18:08</label>--%>
<%--            </div>--%>
<%--            <div style="border-bottom: #8D8D8D solid 1px;">--%>
<%--                <label>评论内容</label>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--    </div>--%>


</div>
<div id="div_br" hidden="hidden" style="width:100%;height:150px;float:left;">

</div>

<div id="did_bottom_div" class="fix_bottom1">
  <div class="shownow" > 对： <label id="pass_question_num">0</label> 题&nbsp;&nbsp;&nbsp;&nbsp;错：<label id="fail_question_num">1</label>题&nbsp;&nbsp;&nbsp;&nbsp;正确率：<label id="pass_percent">0</label>%
    <div style="float: right;margin-right: 25px;" onclick="showNumMenu()"><img src="../my_image/logo_menu.png" width="15" height="15" style="padding-top: 5px;"> <label id="current_index">0</label>/<label id="total_index">0</label></div>
  </div>

    <div class="mymoresost_con" id="num_array_div" hidden="hidden">

    </div>
</div>
<div class="fix_bottom2" id="comment_bottom_div" hidden="hidden">
    <div style="float: left;width: 80%;margin-left: 2%;margin-right: 1%;"><textarea id="comment_input"  placeholder="请输入评论..."  style="width: 100%;height: 27px;" onclick="changeComment_input(75)" onblur="changeComment_input(27)" ></textarea></div>
    <div style="float: right;width: 15%;margin-right: 2%;"><button id="comment_btn" onclick="insertComment()" style="width: 100%;height: 30px;">发表</button></div>
</div>
<%--<div class="myfooter fix_bottom">--%>
<%--    <p>©考神驾到版权所有</p>--%>
<%--    <span>www.kaoshenjiadao.com</span>--%>
<%--</div>--%>

</body>

<script>
    var layer;
    layui.use('layer',function(){
        layer=layui.layer;
    })

    // function test1(){
    //    alert($("#question_class_hide").val());
    //     alert($("#question_chapter_hide").val());
    // }

    var all_data;//question对象数组
    var current_index;//当前的question索引
    var chapter_count_array;
    var count_total;
    var question_history=[];
    var flag_menunum=false;
    var num_menu_array=[];
    window.onload=function(){

        var h=$(window).height()*0.3;
        $("#div_br").attr("style","width:100%;float:left;height:"+h+"px;")

        var question_class_tool=$("#question_class_hide").val();
        if(question_class_tool=="科一"){
            if($("#rand_flag").val()!="yes") {
                if($("#other_class").val()=="") {
                    if($("#question_chapter_hide").val()=="")
                      $("#page_head_title").text("科一顺序练习");
                    else
                        $("#page_head_title").text("科一章节练习");
                }else{
                    $("#page_head_title").text("科一专项练习");
                }
            }
            else
                $("#page_head_title").text("科一随机练习");
        }else{
            if($("#rand_flag").val()!="yes") {
                if($("#other_class").val()=="") {
                    if($("#question_chapter_hide").val()=="")
                        $("#page_head_title").text("科四顺序练习");
                    else
                        $("#page_head_title").text("科四章节练习");
                }else{
                    $("#page_head_title").text("科四专项练习");
                }
            }
            else
                $("#page_head_title").text("科四随机练习");
        }



        //根据不同的参数，初始化所有的试题数据
        $.ajax({
            url:"${pageContext.request.contextPath}/front_question/shunxu_practice_init.do",
            data:{
                "question_class":$("#question_class_hide").val(),
                "question_chapter":$("#question_chapter_hide").val(),
                "rand_flag":$("#rand_flag").val(),
                "other_class":$("#other_class").val(),
                "did_class":$("#did_class").val()
            },
            success:function(data,status){
                if(status=="success"){
                    all_data=data.data;
                    current_index=data.start_index;
                    chapter_count_array=data.count_array;
                    count_total=data.count_total;
                    for(var i=0;i<all_data.length;i++){
                        question_history.push({
                            flag_make:false,
                            option_num:"0"
                        })
                    }
                    changeQuestion(current_index);
                    changeComment_ul(all_data[current_index].question_id);
                    var question_id_array=[];
                    for(var i=0;i<all_data.length;i++){
                        question_id_array.push(all_data[i].question_id);
                    }
                    initFlag_pass_count(question_id_array);

                    $("#current_index").text(current_index+1);
                    $("#total_index").text(all_data.length);
                }
            }
        })
    }

    function initFlag_pass_count(question_id_array){
        $.ajax({
            url:"${pageContext.request.contextPath}/front_question/flag_pass_count_init.do",
            dataType:"json",
            type:"post",
            data:{
                "question_class":$("#question_class_hide").val(),
                "question_chapter":$("#question_chapter_hide").val(),
                "question_id_array":JSON.stringify(question_id_array)
            },
            success:function (data,status){
                if(status=="success"){
                    changeFlag_pass_count(data);
                    num_menu_array=data.num_menu_array;
                }
            }
        })
    }

    function changeQuestion(index){
        if(index>=0){

            //初始化的一些操作
            $("#question_video_div").empty();
            // flag_menunum=false;

            var chapter_num=parseInt(all_data[index].question_chapter.substring(0,1))-1;
            var question_chapter_number_str=all_data[index].question_content.substring(0,all_data[index].question_content.indexOf('、'));
            var question_chapter_number=parseInt(question_chapter_number_str);
            for(var i=0;i<chapter_num;i++){
                question_chapter_number-=chapter_count_array[i];
            }
            var question_chapter_str="第"+all_data[index].question_chapter.substring(0,1)+"章";
            question_chapter_str+=all_data[index].question_chapter.substring(1,all_data[index].question_chapter.length);
            var question_content_str=question_chapter_number+""+all_data[index].question_content.substring(all_data[index].question_content.indexOf('、'),all_data[index].question_content.length);
            //修改试题题干、章节等开始
            $("#question_chapter").text(question_chapter_str);
            $("#question_content").text(question_content_str);
            // $("#question_chapter_number").text(question_chapter_number_str);
            $("#question_chapter_number").text(question_chapter_number);
            $("#question_chapter_count1").text(chapter_count_array[chapter_num]);
            $("#question_chapter_count2").text(chapter_count_array[chapter_num]);
            $("#question_answer").text(all_data[index].question_answer);
            //修改试题题干、章节等结束

            var question_answer=all_data[index].question_answer;

            //显示图片开始
            var question_img=all_data[index].question_img;
            var img_path="${pageContext.request.contextPath}/img_artificial/"+"question_img/";
            if(question_img!=""){
                // <img id="question_img" class="testimg" src="#"/>
                $("#question_img_div").empty();
                var img=$("<img/>").attr({
                    "id":"question_img",
                    "class":"testimg",
                    "src":img_path+question_img
                });
                $("#question_img_div").append(img);
            }else{
                $("#question_img_div").empty();
            }
            //显示图片结束

            //显示视频开始
            var question_video=all_data[index].question_video;
            if(question_video!=""){

                var dot_index=question_video.indexOf(".");
                var src_path_head=img_path+question_video.substring(0,dot_index);
                var end_str=["mp4","ogg","webm","swf"];
                var video=$("<video></video>").attr({
                    "id":"question_video",
                    "controls":"controls",
                    "autoplay":"autoplay",
                    "loop":"loop"
                })
                for(var i=1;i<=3;i++){
                    var source=$("<source/>").attr({
                        "src":src_path_head+"."+end_str[i-1],
                        "type":"video/"+end_str[i-1]
                    })
                    video.append(source);
                }
                var object=$("<object></object>").attr({
                    "data":src_path_head+".mp4",
                    "width":"320",
                    "height":"240"
                });
                var embed=$("<embed/>").attr({
                    "src":src_path_head+".swf",
                    "width":"320",
                    "height":"240"
                })
                object.append(embed);
                video.append(object);
                $("#question_video_div").append(video);

                changeQuestion_video_size();

            }
            //显示视频结束

            //创建试题选项开始
            $("#question_option_ul").empty();
            var input_array=[];

            var option_array=all_data[index].question_option.split("\n");
            if(option_array.length==2){
                $("#many_or_not").text("[判断题]");
                createCheck_one(option_array, input_array);
            }else {
                if (question_answer.length == 1) {
                    $("#many_or_not").text("[单选题]");
                    createCheck_one(option_array, input_array);
                }else{
                    $("#many_or_not").text("[多选题]");
                    createCheck_many(option_array, input_array);
                }
            }
            //创建试题选项结束

            //显示收藏
            $.ajax({
                url:"${pageContext.request.contextPath}/front_collect/init_collect.do",
                data:{
                    "question_id":all_data[index].question_id
                },
                success:function(data,status){
                    if(status=="success"){
                        if(data==0){
                            $("#collect_btn").attr("class","a_collect").text("收藏");
                        }else{
                            $("#collect_btn").attr("class","a_collect_active").text("已收藏");
                        }
                    }
                }
            })

        }else{
            layer.msg("这已经是第一题了");
        }

        $("#answer_feedback_right").attr("hidden","hidden");
        $("#answer_feedback_wrong").attr("hidden","hidden");
        $("#confrim_link").attr("href","javascript:confrim_answer();");

        if(question_history[index].flag_make){
            var check_array=$("#question_option_ul li input");
            var check_link=$("#question_option_ul li p a");
            for(var i=0;i<check_array.length;i++){
                check_array[i].disabled="disabled";
                check_array[i].checked=false;
            }
            for(var i=0;i<check_link.length;i++){
                check_link[i].href="javascript:;";
            }
            var option_num_str=question_history[index].option_num;
            var your_answer="";
            for(var i=0;i<option_num_str.length;i++) {
                var id = "#option" + option_num_str.charAt(i);
                $(id).attr("checked", true);
                your_answer+=$(id).val();
            }
            if(your_answer==all_data[index].question_answer){
                $("#answer_feedback_right").removeAttr("hidden");
            }else{
                $("#answer_feedback_wrong").removeAttr("hidden");
                $("#answer_feedback_wrong").text("答错了，正确答案为："+all_data[index].question_answer);
            }
            $("#confrim_link").removeAttr("href");
        }
    }

    function createCheck_one(option_array,input_array){
        for (var i = 0; i < option_array.length; i++) {
            var li = $("<li></li>");
            var j = i + 1;
            var input = $("<input/>").attr({
                "id": "option" + j,
                "type": "checkbox"
            }).val(option_array[i].substring(0, 1));
            input_array.push(input);
            var p = $("<p></p>");
            var a = $("<a></a>").attr("href", "javascript:option_check(" + j + ",+" + option_array.length + ");").text(option_array[i]);
            p.append(a);
            li.append(input, p);
            $("#question_option_ul").append(li);
        }
        if (input_array.length == 4) {
            input_array[0].click(function () {
                uncheck_other(1, 4);
            })
            input_array[1].click(function () {
                uncheck_other(2, 4);
            })
            input_array[2].click(function () {
                uncheck_other(3, 4);
            })
            input_array[3].click(function () {
                uncheck_other(4, 4);
            })
        } else {
            if (input_array.length == 3) {
                input_array[0].click(function () {
                    uncheck_other(1, 3);
                })
                input_array[1].click(function () {
                    uncheck_other(2, 3);
                })
                input_array[2].click(function () {
                    uncheck_other(3, 3);
                })
            } else {
                input_array[0].click(function () {
                    uncheck_other(1, 2);
                })
                input_array[1].click(function () {
                    uncheck_other(2, 2);
                })
            }
        }
    }
    function createCheck_many(option_array,input_array){
        for (var i = 0; i < option_array.length; i++) {
            var li = $("<li></li>");
            var j = i + 1;
            var input = $("<input/>").attr({
                "id": "option" + j,
                "type": "checkbox"
            }).val(option_array[i].substring(0, 1));
            input_array.push(input);
            var p = $("<p></p>");
            var a = $("<a></a>").attr("href", "javascript:option_check_many(" + j + ");").text(option_array[i]);
            p.append(a);
            li.append(input, p);
            $("#question_option_ul").append(li);
        }
    }



    function last_question(){
        if(current_index>0){
            cancelABorder(current_index);
            current_index--;
            changeQuestion(current_index);
            updateHistory_index(current_index);
            changeComment_ul(all_data[current_index].question_id);
            $("#current_index").text(current_index+1);
        }else{
            layer.msg("这已经是第一题了");
        }
    }
    function next_question(){
        if(current_index<count_total-1) {
            cancelABorder(current_index);
            current_index++;
            changeQuestion(current_index);
            updateHistory_index(current_index);
            changeComment_ul(all_data[current_index].question_id);
            $("#current_index").text(current_index+1);
        }else{
            layer.msg("这已经是最后一题了");

        }
    }

    function updateHistory_index(index){
        $.ajax({
            url:"${pageContext.request.contextPath}/front_question/update_history_index.do",
            data:{
                "history_index":index,
                "question_class":$("#question_class_hide").val(),
                "question_chapter":$("#question_chapter_hide").val(),
                "rand_flag":$("#rand_flag").val(),
                "other_class":$("#other_class").val(),
                "did_class":$("#did_class").val()
            },
            success:function (data,status){

            }
        })
    }

    function uncheck_other(num,length){
        for(var i=1;i<=length;i++){
            var id_tool="option"+i;
            if(i!=num){
                document.getElementById(id_tool).checked=false;
            }
        }
    }

    function option_check(num,length){
        var id="option"+num;
        var check=document.getElementById(id).checked;
        if(check){
            document.getElementById(id).checked=false;
        }else{
            document.getElementById(id).checked=true;
        }
        for(var i=1;i<=length;i++){
            var id_tool="option"+i;
            if(i!=num){
                document.getElementById(id_tool).checked=false;
            }
        }
    }

    function option_check_many(num){
        var id="option"+num;
        var check=document.getElementById(id).checked;
        if(check){
            document.getElementById(id).checked=false;
        }else{
            document.getElementById(id).checked=true;
        }
    }

    function confrim_answer(){

        $("#answer_feedback_right").attr("hidden","hidden");
        $("#answer_feedback_wrong").attr("hidden","hidden");

        var check_array=$("#question_option_ul li input");
        var check_link=$("#question_option_ul li p a");
        var flag=true;
        var j_str="";
        var j;
        var i;
        var your_answer="";
        var flag_choose=false;
        var question_answer=$("#question_answer").text();
        if(question_answer.length==1) {
            for ( i = 0; i < check_array.length; i++) {
                if (check_array[i].checked) {
                    if (check_array[i].value != question_answer) {
                        flag = false;
                    }
                    flag_choose=true;
                    j=i+1;
                    j_str+=j;
                    break;
                }
            }
        }else{
            for ( i = 0; i < check_array.length; i++) {
                if (check_array[i].checked) {
                    your_answer+=check_array[i].value;
                    j=i+1;
                    j_str+=j;
                    flag_choose=true;
                }
            }
            if(your_answer!=question_answer)
                flag=false;
        }
        if(!flag_choose){
            layer.msg("您还没有选择");
        }else {
            //确认后无法再次选择
            for(var i=0;i<check_array.length;i++){
                check_array[i].disabled="disabled";
            }
            for(var i=0;i<check_link.length;i++){
                check_link[i].href="javascript:;";
            }
            $("#confrim_link").removeAttr("href");
            question_history[current_index].flag_make=true;
            question_history[current_index].option_num=j_str;

            var flag_pass=1;
            var question_id=all_data[current_index].question_id;
            var question_class=$("#question_class_hide").val();
            var question_chapter=$("#question_chapter_hide").val();
            if (flag) {
                //答对
                $("#answer_feedback_right").removeAttr("hidden");
                // if($("#next_checkbox").attr("checked")){
                //     next_question();
                // }
            } else {
                //答错
                flag_pass=0;
                $("#answer_feedback_wrong").removeAttr("hidden");
                $("#answer_feedback_wrong").text("答错了，正确答案为："+question_answer);
            }
            updateUser_question_table(question_id,flag_pass,question_class,question_chapter,flag);
        }
    }
    function updateUser_question_table(question_id,flag_pass,question_class,question_chapter,flag){
        $.ajax({
            url:"${pageContext.request.contextPath}/front_question/update_user_question_table.do",
            data:{
                "question_id":question_id,
                "flag_pass":flag_pass,
                "question_class":question_class,
                "question_chapter":question_chapter
            },
            success:function(data,status){
                if(status=="success"){
                    var map={
                        "pass_num":parseInt($("#pass_question_num").text()),
                        "fail_num":parseInt($("#fail_question_num").text()),
                        "pass_percent":parseFloat($("#pass_percent").text())
                    };
                    if(data==0){
                        if(flag_pass==0){
                            map.fail_num++;
                            num_menu_array[current_index]=0;
                        }else{
                            map.pass_num++;
                            num_menu_array[current_index]=1;
                        }
                    }else{
                        //做过且原来做错
                        if(data==1){
                            if(flag_pass==1){
                                map.fail_num--;
                                map.pass_num++;
                                num_menu_array[current_index]=1;
                            }
                        }
                    }
                    map.pass_percent=0.0;
                    if(map.pass_num!=0||map.fail_num!=0) {
                        map.pass_percent = (map.pass_num) / (map.pass_num + map.fail_num);
                        map.pass_percent*=100;
                        map.pass_percent=Math.round(map.pass_percent*10)/10;
                    }
                    // alert(map.pass_num);
                    // alert(map.fail_num);
                   changeFlag_pass_count(map);
                   changeCurrentA(current_index);

                    if(flag){
                        if($("#next_checkbox").attr("checked")){
                            next_question();
                        }
                    }
                }
            }
        })
    }
    function changeFlag_pass_count(data){
        var pass_num=data.pass_num;
        var fail_num=data.fail_num;
        var pass_percent=data.pass_percent;
        $("#pass_question_num").text(pass_num);
        $("#fail_question_num").text(fail_num);
        $("#pass_percent").text(pass_percent);
    }

    function change_next_checkbox(){
        if($("#next_checkbox").attr("checked")){
            $("#next_checkbox").attr("checked",false);
        }else{
            $("#next_checkbox").attr("checked",true);
        }
    }

    function changeQuestion_video_size(){
        var w=$(window).width()*0.95;
        $("#question_video").attr({
            "width":w,
            "height":170
        });
    }
    window.addEventListener("resize", function(){
        changeQuestion_video_size();
    });









    //评论有关

    //点赞图片改变
    function changeValue_img(comment_id){
        var id_head="#value_img";
        var id=id_head+comment_id;
        var id_head_label="#comment_value_label";
        var id_label=id_head_label+comment_id;
        if($(id).attr("src")=="images/value.png"){
            $(id).attr("src","images/value_active.png");
            var num=parseInt($(id_label).text())+1;
            $(id_label).text(num+" ");
            updateComment_value(comment_id,num,1);

        }else{
            $(id).attr("src","images/value.png");
            var num=parseInt($(id_label).text())-1;
            $(id_label).text(num+" ");
            updateComment_value(comment_id,num,0);
        }
    }

    //更新点赞量
    function updateComment_value(comment_id,comment_value,flag){
        $.ajax({
            url:"${pageContext.request.contextPath}/front_comment/update_comment_value.do",
            data:{
                "comment_id":comment_id,
                "comment_value":comment_value,
                "flag":flag
            },
            success:function (data,status){
                if(status=="success"){

                }
            }
        })
    }
    function to_img_detail(user_nickname,sex,user_img){
        var w=$(window).width()*0.55;
        var h=$(window).height()*0.35;
        var sex_icon="♀";
        if(sex==1)
            sex_icon="♂"
        layer.open({
            type:2,
            title:user_nickname+sex_icon,
            area:[w+'px',h+'px'],
            shadeClose:true,
            content:"img_detail.jsp?user_img_hidden="+user_img,
        })
    }
    function showComment(){
        if($("#comment_checkbox").attr("checked")){
            $("#comment_title_div").attr("hidden",true);
            $("#comment_div").attr("hidden",true);
            $("#div_br").attr("hidden",true);
            $("#comment_checkbox").attr("checked",false);

            $("#comment_bottom_div").attr("hidden",true);
            $("#did_bottom_div").removeAttr("hidden");
        }else{
            $("#comment_title_div").removeAttr("hidden");
            $("#comment_div").removeAttr("hidden");
            $("#div_br").removeAttr("hidden");
            $("#comment_checkbox").attr("checked",true);

            // $("#comment_bottom_div").attr("hidden",true);
            // $("#did_bottom_div").removeAttr("hidden");
        }
    }
    function changeComment_input(num){
        $("#comment_input").attr("style","width:100%;height:"+num+"px;");
        if(num==75){
            $("#comment_btn").text("确认");
        }else{
            $("#comment_btn").text("发表");
        }
    }
    window.onscroll=function(){
        if (document.body.scrollTop > 10 || document.documentElement.scrollTop > 10) {
            if(!$("#comment_title_div").attr("hidden")){
                $("#did_bottom_div").attr("hidden",true);
                $("#comment_bottom_div").removeAttr("hidden");
            }
        } else {
            $("#comment_bottom_div").attr("hidden",true);
            $("#did_bottom_div").removeAttr("hidden");
        }
    }
    function insertComment(){
        var comment_des=$("#comment_input").val();
        if(comment_des==""){
            layer.msg("评论不能为空");
            return;
        }
        var question_id=all_data[current_index].question_id;
        $.ajax({
            url:"${pageContext.request.contextPath}/front_comment/insert_comment.do",
            data:{
                "question_id":question_id,
                "comment_des":comment_des
            },
            success:function (data,status){
                if(status=="success"){
                    if(data.flag==1){
                        layer.msg("评论发表成功");
                        changeComment_ul(all_data[current_index].question_id);
                    }else{
                        layer.alert("发表失败，评论中存在不合法字符（有可能是表情什么的，请检查）");
                    }
                }
            }
        })
    }
    function changeComment_ul(question_id){
        $.ajax({
            url:"${pageContext.request.contextPath}/front_comment/change_comment.do",
            data:{
                "question_id":question_id
            },
            success:function(data,status){
                if(status=="success"){
                    $("#comment_div").empty();
                    // $("#div_br").attr("style","width:100%;height:80px;float:left;");
                    if(data.commentList.length==0){
                        $("#comment_div").text("暂无评论");
                    }else {
                        for (var i = 0; i < data.commentList.length; i++) {
                            var div_parent = $("<div></div>").attr("style", "margin-top: 15px;width: 100%;float:left;");
                            var div_img = $("<div></div>").attr("style","float:left;width: 12%;margin-left: 5px;");
                            var user_img="${pageContext.request.contextPath}/img_artificial/user_img/"+data.userList[i].user_img;
                            var a_img=$("<a></a>").attr("href","javascript:to_img_detail('"+data.userList[i].user_nickname+"',"+data.userList[i].sex+",'"+user_img+"');");
                            var img=$("<img>").attr({
                                "src":user_img,
                                "width":50,
                                "height":50,
                                "style":"border:0px solid #e0e0e0; border-radius:25%;"
                            })
                            a_img.append(img);
                            div_img.append(a_img);
                            var div_right_parent=$("<div></div>").attr("style","float:right;width: 84%;margin-left: 5px;");
                            var div_right_1=$("<div></div>");
                            var div_user_nickname=$("<div></div>").attr("style","float:left;width: 80%;");
                            var user_nickname_label=$("<label></label>").attr("style","color: #8D8D8D").text(data.userList[i].user_nickname);
                            div_user_nickname.append(user_nickname_label);
                            var div_comment_value=$("<div></div>").attr("style","float:right;width: 20%;");
                            var div_comment_value_num=$("<div></div>").attr("style","margin-top: 4px;float: left;");
                            var comment_value_num_label=$("<label></label>").attr({
                                "style":"color: #8D8D8D;",
                                "id":"comment_value_label"+data.commentList[i].comment_id
                            }).text(data.commentList[i].comment_value+" ");
                            div_comment_value_num.append(comment_value_num_label);
                            var a_comment_value_img=$("<a></a>").attr("href","javascript:changeValue_img("+data.commentList[i].comment_id+");");
                            var value_img="images/value.png";
                            if(data.flagList[i]==1){
                                value_img="images/value_active.png";
                            }
                            var comment_value_img=$("<img>").attr({
                                "id":"value_img"+data.commentList[i].comment_id,
                                "src":value_img,
                                "width":25,
                                "height":25
                            });
                            a_comment_value_img.append(comment_value_img);
                            div_comment_value.append(div_comment_value_num,a_comment_value_img);
                            div_right_1.append(div_user_nickname,div_comment_value);
                            var div_right_2=$("<div></div>");
                            var comment_time=new Date(parseInt(data.commentList[i].comment_time)).toLocaleString().replace(/:\d{1,2}$/,' ');
                            var label_comment_time=$("<label></label>").attr("style","color: #8D8D8D").text("评论于："+comment_time);
                            div_right_2.append(label_comment_time);
                            var div_right_3=$("<div></div>").attr("style","border-bottom: #8D8D8D solid 1px;");
                            var label_comment_des=$("<label></label>").text(data.commentList[i].comment_des);
                            div_right_3.append(label_comment_des);
                            div_right_parent.append(div_right_1,div_right_2,div_right_3);
                            div_parent.append(div_img,div_right_parent);

                            $("#comment_div").append(div_parent);
                        }
                    }
                    <%--<div style="margin-top: 15px;width: 100%;float:left;">--%>
                    <%--    <div style="float:left;width: 12%;margin-left: 5px;">--%>
                    <%--        <a href="javascript:to_img_detail('小红',0,'${pageContext.request.contextPath}/img_artificial/user_img/beauty2.jpg');">--%>
                    <%--            <img src="${pageContext.request.contextPath}/img_artificial/user_img/beauty2.jpg" width="50px" height="50px">--%>
                    <%--        </a>--%>
                    <%--    </div>--%>
                    <%--    <div style="float:right;width: 84%;margin-left: 5px;">--%>
                    <%--        <div>--%>
                    <%--            <div style="float:left;width: 80%;"><label style="color: #8D8D8D">小明</label></div>--%>
                    <%--            <div style="float:right;width: 20%;"><div style="margin-top: 4px;margin-bottom: 0px;float: left;"><label style="color: #8D8D8D;">0 &nbsp;</label></div> <a href="javascript:changeValue_img(1);"><img id="value_img1" src="images/value.png" width="25" height="25"> </a></div>--%>
                    <%--        </div>--%>
                    <%--        <div>--%>
                    <%--            <label style="color: #8D8D8D">评论于：</label><label style="color: #8D8D8D">2022-1-28 下午18:08</label>--%>
                    <%--        </div>--%>
                    <%--        <div style="border-bottom: #8D8D8D solid 1px;">--%>
                    <%--            <label>评论内容</label>--%>
                    <%--        </div>--%>
                    <%--    </div>--%>
                    <%--</div>--%>
                }
            }
        })
    }


    //收藏有关
    function collect_question(){
        var flag=1;
        if($("#collect_btn").attr("class")=="a_collect"){
            $("#collect_btn").attr("class","a_collect_active").text("已收藏");
        }else{
            flag=0;
            $("#collect_btn").attr("class","a_collect").text("收藏");
        }
        $.ajax({
            url:"${pageContext.request.contextPath}/front_collect/collect_question.do",
            data:{
                "question_id":all_data[current_index].question_id,
                "flag":flag
            },
            success:function (data,status){

            }
        })
    }

    function showNumMenu(){
        if(!flag_menunum) {
            initNumMenu();
            flag_menunum = true;
        }
        if(!$("#num_array_div").attr("hidden")){
            $("#num_array_div").attr("hidden",true);
        }else{
            $("#num_array_div").removeAttr("hidden");
            changeCurrentA(current_index);
            document.getElementById("num_array_div").scrollTop=0;
            document.getElementById("num_array_div").scrollTop+=Math.floor((current_index+1)/5)*42;
        }
    }

    function initNumMenu(){
        $("#num_array_div").empty();
        for(var i=0;i<all_data.length;i++){
            var span=$("<span></span>");
            var j=i+1;
            var a=$("<a></a>").attr({
                "id":"span_a"+j,
                "href":"javascript:changeIndex("+i+");"
            }).text(j+"");
            if(num_menu_array[i]==0){
                a.attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid #e0e0e0; text-align:center;text-decoration: none;color: DimGray;background-color: #ff6600;");
            }else{
                if(num_menu_array[i]==1)
                a.attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid #e0e0e0; text-align:center;text-decoration: none;color: DimGray;background-color: #01a474;");
            }
            span.append(a);
            $("#num_array_div").append(span);
        }
    }
    function changeIndex(index){

        // changeCurrentA(index);
        cancelABorder(current_index);
        current_index=index;
        $("#current_index").text(index+1);
        $("#num_array_div").attr("hidden",true);
        changeQuestion(index);
        changeComment_ul(all_data[index].question_id);
        updateHistory_index(index);
    }
    function changeCurrentA(index){
        var tool=index+1;
        if(num_menu_array[index]==-1)
            $("#span_a"+tool).attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid Aqua; text-align:center;text-decoration: none;color: Aqua;");
        else{
            if(num_menu_array[index]==0){
                $("#span_a"+tool).attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid Aqua; text-align:center;text-decoration: none;color: Aqua;background-color: #ff6600;");
            }else{
                $("#span_a"+tool).attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid Aqua; text-align:center;text-decoration: none;color: Aqua;background-color: #01a474;");
            }
        }
    }
    function cancelABorder(index){
        var tool=index+1;
        if(num_menu_array[index]==-1)
            $("#span_a"+tool).attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid #e0e0e0; text-align:center;text-decoration: none;color: DimGray;");
        else{
            if(num_menu_array[index]==0){
                $("#span_a"+tool).attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid #e0e0e0; text-align:center;text-decoration: none;color: DimGray;background-color: #ff6600;");
            }else{
                $("#span_a"+tool).attr("style","width:92.94871794871795%; display:block; height:30px; margin:5px auto; line-height:30px; border:1px solid #e0e0e0; text-align:center;text-decoration: none;color: DimGray;background-color: #01a474;");
            }
        }
    }
</script>

























<!--考试页js-->
<script>
 $(".thisexplain").click(function(){
	 $(".explain_tan").show();
	 })
 $(".close").click(function(){
	 $(".explain_tan").hide();
	 })
</script>
<!--考试页js-->
<!--头部高度赋给列表的topjs-->
<script>
   var heighttop=$(".top").height();
   $(".topmenu").css("top",heighttop);
    $(".menumore").toggle(function(){
	     $(".topmenu").show(); 
	   },function(){
	     $(".topmenu").hide(); 
	 	   })
   $(".buttontop").click(function(){
	     $(".topmenu").hide();  
	   })
	   
 $(function(){
	 $(".tasecartop span a").click(function(){
		  var $banktip=$(this).attr("tip");
		  $($banktip).show().siblings().hide();
		  $(".tasecartop span a").removeClass("payaclik");
		  $(this).addClass("payaclik");
		 })
	
	})
 </script>
 
<!--头部高度赋给列表的topjs-->
<!--banner将图片的高度赋给父级扪js-->
<script>
   var heighta=$("###incltialiu li:eq(0) img").height();
   $(".main,.width,###incltialiu").height(heighta) ;
 </script>
 <!--banner将图片的高度赋给父级扪js-->
<!--首页标题点击出现更多分类js-->
 <script>
	$(".titlemore").toggle(function(){
		$(this).parent(".tabtila").siblings(".moresort").show()
		$(this).children("img").attr("src","images/title_692.jpg")
		},function(){
		$(this).parent(".tabtila").siblings(".moresort").hide()
		$(this).children("img").attr("src","images/title_69.jpg")
		})
  </script>
 <!--首页标题点击出现更多分类js-->
</html>
